﻿package mortal.game.view.copy.sunbathCopy.view
{
    import com.gengine.global.*;
    import com.gengine.resource.*;
    import com.gengine.resource.info.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.display.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.copy.*;
    import mortal.game.view.vip.*;
    import mortal.game.view.vip.panel.*;
    import mortal.mvc.core.*;

    public class SunbathCopyInfoView extends CopyInfoPanelBase
    {
        private var _bg:ScaleBitmap;
        protected var _tipBg:ScaleBitmap;
        private var _bmpTitle:GBitmap;
        private var _leaveBtn:GLoadingButton;
        private var _exp:BitmapNumberText;
        private var _anima:BitmapNumberText;
        private var _btnContainer:GSprite;
        private var _btnExpand:GBitmap;
        private var _txtTips:GTextFiled;
        private var _expVipTip:VipOpenTipsPanel;
        private var _manoVipTip:VipOpenTipsPanel;
        protected var _manoTxt:GTextFiled;
        protected var _expAddTxt:GTextFiled;
        private var _vipType:int = 38;
        private var _isDescExpanding:Boolean = true;
        private static var _instance:SunbathCopyInfoView;

        public function SunbathCopyInfoView()
        {
            super(ImagesConst.copyInfoPanelTitle_sunbath, 271);
            return;
        }// end function

        private function onLeave(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.CopyClickQuickBtn));
            return;
        }// end function

        private function onSunBathOperRes(param1:Object = null) : void
        {
            this._exp.text = Cache.instance.copy.sunbath.exp.toString();
            this._anima.text = Cache.instance.copy.sunbath.vitalEnergy.toString();
            this.updateVip();
            return;
        }// end function

        private function updateVip() : void
        {
            var _loc_1:int = 0;
            var _loc_2:Number = NaN;
            var _loc_3:Number = NaN;
            if (VipUtil.isVipReachLevelByType(this._vipType))
            {
                var _loc_4:Boolean = true;
                this._manoTxt.visible = true;
                this._expAddTxt.visible = _loc_4;
                _loc_1 = 0;
                _loc_2 = VipUtil.getCurValueByType(this._vipType);
                _loc_3 = _loc_2 + 100;
                _loc_3 = _loc_2 / _loc_3;
                _loc_1 = Cache.instance.copy.sunbath.exp;
                _loc_1 = _loc_1 * _loc_3;
                this._expAddTxt.text = Language.getStringByParam(70969, _loc_1);
                _loc_1 = Cache.instance.copy.sunbath.vitalEnergy;
                _loc_1 = _loc_1 * _loc_3;
                this._manoTxt.text = Language.getStringByParam(70969, _loc_1);
            }
            else
            {
                var _loc_4:Boolean = false;
                this._manoTxt.visible = false;
                this._expAddTxt.visible = _loc_4;
            }
            return;
        }// end function

        override public function stageResize() : void
        {
            super.stageResize();
            x = Global.stage.stageWidth - 255;
            y = 150;
            return;
        }// end function

        private function onResCompl() : void
        {
            if (isDisposed)
            {
                return;
            }
            this._bmpTitle.bitmapData = GlobalClass.getBitmapData(ImagesConst.SunbathCopy_HDSY);
            this._btnExpand.bitmapData = GlobalClass.getBitmapData(ImagesConst.SunbathCopy_Expand);
            pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.SunbathCopyTxt1, 16, 56, _bodySprite));
            pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.SunbathCopyTxt2, 16, 115, _bodySprite));
            pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.SunbathCopy_HDGZ, 109, 191, _bodySprite));
            return;
        }// end function

        private function expandBg() : void
        {
            if (isDisposed)
            {
                return;
            }
            _bodySprite.addChild(this._txtTips);
            this._bg.width = 271;
            this._bg.height = 548;
            this._leaveBtn.y = 493;
            this._tipBg.visible = true;
            return;
        }// end function

        private function unexpandBg() : void
        {
            if (isDisposed)
            {
                return;
            }
            DisplayUtil.removeMe(this._txtTips);
            this._bg.width = 271;
            this._bg.height = 290;
            this._leaveBtn.y = 240;
            this._tipBg.visible = false;
            return;
        }// end function

        private function imgLoaded(param1:SWFInfo) : void
        {
            if (isDisposed)
            {
                return;
            }
            this._bg.resetBitmapDataAndScale9Grid(param1.bitmapData, ResourceConst.getRectangle(ImagesConst.SunbathCopyInfoBg));
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bg = UIFactory.bg(0, 0, 252, 502, _bodySprite);
            this._tipBg = UIFactory.bg(10, 233, 250, 258, _bodySprite, ImagesConst.PanelBg);
            this._tipBg.visible = false;
            this._bmpTitle = UIFactory.gBitmap(null, 100, 14, _bodySprite);
            this._exp = UIFactory.bitmapNumberText(111, 57, "SunbathCopyNum1.png", 19, 24, 2, _bodySprite, 10);
            this._anima = UIFactory.bitmapNumberText(111, 117, "SunbathCopyNum1.png", 19, 24, 2, _bodySprite, 10);
            this._leaveBtn = UIFactory.gLoadingButton(ResFileConst.SunbathCopyLeaveBtn, 80, 445, 103, 40, _bodySprite);
            this._expVipTip = UIFactory.getUICompoment(VipOpenTipsPanel, 33, 90, _bodySprite);
            this._expVipTip.valueType = VipOpenTipsPanel.percentValue;
            this._expVipTip.resetLevelTextPos(61, 1, 33, 1);
            this._expVipTip.resetValueTextPos(155, 1, 97, 1);
            this._expVipTip.resetTipsTextPos(0, 0, 0, 0);
            this._expVipTip.bgUrl = "";
            this._expVipTip.vipType = 44;
            this._manoVipTip = UIFactory.getUICompoment(VipOpenTipsPanel, 33, 149, _bodySprite);
            this._manoVipTip.valueType = VipOpenTipsPanel.percentValue;
            this._manoVipTip.resetLevelTextPos(61, 1, 33, 1);
            this._manoVipTip.resetValueTextPos(155, 1, 97, 1);
            this._manoVipTip.resetTipsTextPos(0, 0, 0, 0);
            this._manoVipTip.bgUrl = "";
            this._manoVipTip.vipType = 45;
            this._manoTxt = UIFactory.gTextField("", 145, 147, 150, 25, _bodySprite, GlobalStyle.textFormatLv.setSize(13).setBold(true));
            this._expAddTxt = UIFactory.gTextField("", 145, 88, 150, 25, _bodySprite, GlobalStyle.textFormatLv.setSize(13).setBold(true));
            var _loc_2:Boolean = true;
            this._manoTxt.visible = true;
            this._expAddTxt.visible = _loc_2;
            this._btnContainer = UICompomentPool.getUICompoment(GSprite) as GSprite;
            _bodySprite.addChild(this._btnContainer);
            this._btnContainer.mouseChildren = true;
            this._btnContainer.mouseEnabled = true;
            this._btnExpand = UIFactory.gBitmap(null, 19, 211, this._btnContainer);
            this._btnContainer.configEventListener(MouseEvent.MOUSE_OVER, this.mouseOverContainerHandler);
            this._btnContainer.configEventListener(MouseEvent.MOUSE_OUT, this.mouseOutContainerHandler);
            this._btnContainer.configEventListener(MouseEvent.CLICK, this.expandDescHandler);
            this._leaveBtn.configEventListener(MouseEvent.CLICK, this.onLeave);
            var _loc_1:* = GlobalStyle.textFormatLv;
            _loc_1.leading = 4;
            this._txtTips = UIFactory.gTextField("", 17, 236, 226, 270, _bodySprite, _loc_1);
            this._txtTips.htmlText = Language.getString(20270);
            this._txtTips.multiline = true;
            this._txtTips.wordWrap = true;
            this.onSunBathOperRes();
            LoaderHelp.addResCallBack(ResFileConst.sunbathCopy, this.onResCompl);
            NetDispatcher.addCmdListener(ServerCommand.SunBathOperRes, this.onSunBathOperRes);
            NetDispatcher.addCmdListener(ServerCommand.SunbathInfoViewUpdate, this.onSunBathOperRes);
            this._isDescExpanding = false;
            this.unexpandBg();
            LoaderManager.instance.load(ImagesConst.SunbathCopyInfoBg + ".swf", this.imgLoaded);
            return;
        }// end function

        private function mouseOverContainerHandler(event:MouseEvent) : void
        {
            var _loc_2:Number = 1.07;
            this._btnExpand.scaleY = 1.07;
            this._btnExpand.scaleX = _loc_2;
            this._btnExpand.x = 13;
            this._btnExpand.y = 211;
            return;
        }// end function

        private function mouseOutContainerHandler(event:MouseEvent) : void
        {
            var _loc_2:int = 1;
            this._btnExpand.scaleY = 1;
            this._btnExpand.scaleX = _loc_2;
            this._btnExpand.x = 19;
            this._btnExpand.y = 210;
            return;
        }// end function

        private function expandDescHandler(param1) : void
        {
            this._isDescExpanding = !this._isDescExpanding;
            if (this._isDescExpanding)
            {
                this.expandBg();
            }
            else
            {
                this.unexpandBg();
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            LoaderHelp.removeResEvent(ResFileConst.sunbathCopy, this.onResCompl);
            NetDispatcher.removeCmdListener(ServerCommand.SunBathOperRes, this.onSunBathOperRes);
            NetDispatcher.removeCmdListener(ServerCommand.SunbathInfoViewUpdate, this.onSunBathOperRes);
            this._exp.dispose(param1);
            this._anima.dispose(param1);
            this._leaveBtn.dispose(param1);
            this._tipBg = null;
            this._exp = null;
            this._anima = null;
            this._leaveBtn = null;
            this._bmpTitle.dispose(param1);
            this._bmpTitle = null;
            this._bg.dispose(param1);
            this._bg = null;
            this._btnContainer.dispose(param1);
            this._btnContainer = null;
            this._btnExpand.dispose(param1);
            this._btnExpand = null;
            this._txtTips.dispose(param1);
            this._txtTips = null;
            this._expVipTip = null;
            this._manoVipTip = null;
            this._manoTxt = null;
            this._expAddTxt = null;
            return;
        }// end function

        public static function get instance() : SunbathCopyInfoView
        {
            if (_instance == null)
            {
                _instance = new SunbathCopyInfoView;
            }
            return _instance;
        }// end function

    }
}
